home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <devices/audio.h>
- #include <graphics/gfxbase.h>
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <exec/libraries.h>
- #include <libraries/mui.h>
- #include <hardware/custom.h>
- #include <exec/memory.h>
-
- #include <clib/alib_protos.h>
- #include <clib/exec_protos.h>
- #include <proto/muimaster.h>
-
- #include "GUI.h"
-
-
- struct IOAudio *AudioIO=0; /* Pointer to the I/O block for I/O commands */
- struct IOAudio *AudioIO2=0; /* Pointer to the I/O block for I/O commands */
- struct MsgPort *AudioMP=0; /* Pointer to a port so the device can reply */
- struct MsgPort *AudioMP2=0; /* Pointer to a port so the device can reply */
- struct Message *AudioMSG=0; /* Pointer for the reply message */
- struct Message *AudioMSG2=0; /* Pointer for the reply message */
-
- LONG clock = 3579545; /* Clock constant, 3546895 for PAL */
- LONG samples = 16; /* Number of sample bytes */
- LONG samcyc = 1; /* Number of cycles in the sample */
- ULONG device;
- ULONG device2;
- ULONG devicet;
-
- BYTE *waveptr = 0; /* pointer to sine wave in chip mem */
-
-
- /* extern struct Custom custom; */
-
- /* /// "sinewave" */
- BYTE sinewave[16] = {
- 0,45,
- 90,115,
- 127,115,
- 90,45,
- 0,-45,
- -90,-115,
- -127,-115,
- -90,-45
- };
-
- /* /// */
-
- /* /// "OpenAudio" */
- int OpenAudio(LONG volume)
- {
- struct GfxBase *GfxBase;
-
- UBYTE whichannel[1];
- UBYTE whichannel2[1];
-
- if (volume<0)
- {
- whichannel[0] = 1; /* left channels */
- whichannel2[0] = 8;
- }
- else
- {
- whichannel[0] = 2; /* right channels */
- whichannel2[0] = 4;
- }
-
- if (volume<0) volume*=-1;
-
- /*-------------------------------------------------------------------------*/
- /* Ask the system if we are PAL or NTSC and set clock constant accordingly */
- /*-------------------------------------------------------------------------*/
-
- GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L);
- if (GfxBase == NULL) return FALSE;
-
- if (GfxBase->DisplayFlags & PAL)
- clock = 3546895; /* PAL clock */
- else
- clock = 3579545; /* NTSC clock */
-
- if (GfxBase) CloseLibrary((struct Library *) GfxBase);
-
- waveptr=AllocVec(samples,MEMF_CHIP);
- if (!waveptr) return FALSE;
- CopyMem(sinewave,waveptr,samples);
-
- /* --- 1. Kanal allozieren --------------------- */
-
- AudioIO = (struct IOAudio *)AllocVec( sizeof(struct IOAudio),MEMF_PUBLIC | MEMF_CLEAR);
- if (AudioIO == 0) return FALSE;
-
- AudioMP = CreatePort(0,0);
- if (AudioMP == 0) return FALSE;
-
- AudioIO->ioa_Request.io_Message.mn_ReplyPort = AudioMP;
- AudioIO->ioa_Request.io_Message.mn_Node.ln_Pri = 127;
- AudioIO->ioa_Request.io_Command = ADCMD_ALLOCATE;
- AudioIO->ioa_Request.io_Flags = ADIOF_NOWAIT;
- AudioIO->ioa_AllocKey = 0;
- AudioIO->ioa_Data = whichannel;
- AudioIO->ioa_Length = sizeof(whichannel);
-
- device = OpenDevice("audio.device",0L, (struct IORequest *) AudioIO ,0L);
- if (device != 0) return FALSE;
-
- AudioIO->ioa_Request.io_Message.mn_ReplyPort =AudioMP;
- AudioIO->ioa_Request.io_Command =CMD_WRITE;
- AudioIO->ioa_Request.io_Flags =ADIOF_PERVOL;
- AudioIO->ioa_Data =waveptr;
- AudioIO->ioa_Length =16;
- AudioIO->ioa_Volume =volume;
- AudioIO->ioa_Cycles =0;
-
-
- /* --- 2. Kanal allozieren --------------------- */
-
- AudioIO2 = (struct IOAudio *)AllocVec( sizeof(struct IOAudio),MEMF_PUBLIC | MEMF_CLEAR);
- if (AudioIO2 == 0) return FALSE;
-
- AudioMP2 = CreatePort(0,0);
- if (AudioMP2 == 0) return FALSE;
-
- AudioIO2->ioa_Request.io_Message.mn_ReplyPort = AudioMP2;
- AudioIO2->ioa_Request.io_Message.mn_Node.ln_Pri = 127;
- AudioIO2->ioa_Request.io_Command = ADCMD_ALLOCATE;
- AudioIO2->ioa_Request.io_Flags = ADIOF_NOWAIT;
- AudioIO2->ioa_AllocKey = 0;
- AudioIO2->ioa_Data = whichannel2;
- AudioIO2->ioa_Length = sizeof(whichannel2);
-
- device2 = OpenDevice("audio.device",0L, (struct IORequest *) AudioIO2 ,0L);
- if (device2 != 0) return FALSE;
-
- AudioIO2->ioa_Request.io_Message.mn_ReplyPort =AudioMP2;
- AudioIO2->ioa_Request.io_Command =CMD_WRITE;
- AudioIO2->ioa_Request.io_Flags =ADIOF_PERVOL;
- AudioIO2->ioa_Data =waveptr;
- AudioIO2->ioa_Length =16;
- AudioIO2->ioa_Volume =volume;
- AudioIO2->ioa_Cycles =0;
-
- return TRUE;
- }
- /* /// */
-
- /* /// "DualTone" */
- int DualTone(char digit, ULONG delay)
- {
- int F1,F2, i=0;
-
- switch (digit)
- {
- case '0' : F1=1336; F2=941; break;
- case '1' : F1=1209; F2=697; break;
- case '2' : case 'A':case 'B':case 'C': F1=1336; F2=697; break;
- case '3' : case 'D':case 'E':case 'F': F1=1477; F2=697; break;
- case '4' : case 'G':case 'H':case 'I': F1=1209; F2=770; break;
- case '5' : case 'J':case 'K':case 'L': F1=1336; F2=770; break;
- case '6' : case 'M':case 'N':case 'O': F1=1477; F2=770; break;
- case '7' : case 'P':case 'Q':case 'R':case 'S': F1=1209; F2=852; break;
- case '8' : case 'T':case 'U':case 'V': F1=1336; F2=852; break;
- case '9' : case 'W':case 'X':case 'Y':case 'Z': F1=1477; F2=852; break;
- case '*' : F1=1209; F2=941; break;
- case '#' : F1=1477; F2=941; break;
- }
-
- if (!AudioIO) return FALSE;
-
- AudioIO->ioa_Period =clock*samcyc/(samples*F1);
- AudioIO2->ioa_Period=clock*samcyc/(samples*F2);
-
- BeginIO((struct IORequest *) AudioIO );
- BeginIO((struct IORequest *) AudioIO2 );
-
- /* TimeDelay sometimes returns an error. try it 50 times */
- while (++i<50 && TimeDelay(UNIT_MICROHZ,0,delay*1000)==-1);
-
- AbortIO((struct IORequest *) AudioIO );
- AbortIO((struct IORequest *) AudioIO2 );
- }
- /* /// */
-
- /* /// "CloseAudio" */
- CloseAudio()
- {
- if (device == 0) CloseDevice( (struct IORequest *) AudioIO );
- if (AudioMP) DeletePort(AudioMP);
- if (AudioIO) FreeVec( AudioIO );
-
- if (device2==0) CloseDevice( (struct IORequest *) AudioIO2 );
- if (AudioMP) DeletePort(AudioMP2);
- if (AudioIO) FreeVec( AudioIO2 );
-
- if (waveptr) FreeVec(waveptr);
-
- AudioMP=NULL;
- AudioMP2=NULL;
- AudioIO=NULL;
- AudioIO2=NULL;
- waveptr=NULL;
- }
- /* /// */
-
- /* ///------------------------------ "Dial" ------------------------------ */
- void Dial(struct ObjApp *App, char *number, int level)
- {
- int i, j;
- char *str=malloc(32);
- char *plusnum=malloc(32);
- LONG WaitDelay;
- LONG PauseDelay;
- LONG ToneDelay;
- LONG b;
-
- if (level==0)
- {
- get(App->SL_AudioLR, MUIA_Slider_Level, &b); /* ask for position of left/right slider */
- if (!OpenAudio(b)) { CloseAudio(); DisplayBeep(NULL); return; }
- }
-
- get(App->SL_Length, MUIA_Slider_Level, &ToneDelay);
- get(App->SL_Pause, MUIA_Slider_Level, &PauseDelay);
- get(App->SL_Wait, MUIA_Slider_Level, &WaitDelay);
- get(App->STR_DialCode, MUIA_String_Contents, &plusnum);
-
- ToneDelay*=10;
- PauseDelay*=10;
- WaitDelay*=10;
-
- get(App->CH_system, MUIA_Selected, &b);
- get(App->STR_system, MUIA_String_Contents, &str);
- if (b && level==0) Dial(App,str,1); /* dial telephone system pre-code */
-
- /* see if 'Conceal ID' checkbox is selected and
- dial *31# to turn off number transmission */
- get(App->CH_Conceal, MUIA_Selected, &b);
- if (b && level==0) Dial(App,"*31#",1);
-
- for (i=0; i<strlen(number); i++)
- {
- j=0;
- if (number[i]=='!')
- while (++j<50 && TimeDelay(UNIT_MICROHZ,0,WaitDelay*1000)==-1); /* TimeDelay sometimes returns an error. try it 50 times */
-
- if (level==0 && number[i]=='+') Dial(App,plusnum,1);
-
- if ( (number[i]>='0' && number[i]<='9') ||
- (number[i]>='A' && number[i]<='Z') ||
- number[i]=='*' || number[i]=='#' )
- {
- j=0;
- DualTone(number[i],ToneDelay);
- /* TimeDelay sometimes returns an error. try it 50 times */
- while (++j<50 && TimeDelay(UNIT_MICROHZ,0,PauseDelay*1000)==-1);
- }
- }
- free(str);
- free(plusnum);
-
- if (level==0) CloseAudio();
- }
- /* /// ----------------------------------------------------------------- */
-
-
-
- /* /// "old DualTone function with hardware audio" */
- /*
- void DualTone(char digit, ULONG delay)
- {
- UWORD T1, T2;
- void *SnWave = AllocVec(sizeof(SnWaveData),MEMF_CHIP);
-
- if (!SnWave) return;
-
- CopyMem(SnWaveData,SnWave,sizeof(SnWaveData));
-
- switch (digit)
- {
- case '0' : T1=238; T2=166; break;
- case '1' : T1=319; T2=186; break;
- case '2' :case 'A':case 'B':case 'C': T1=319; T2=166; break;
- case '3' :case 'D':case 'E':case 'F': T1=319; T2=151; break;
- case '4' :case 'G':case 'H':case 'I': T1=290; T2=184; break;
- case '5' :case 'J':case 'K':case 'L': T1=290; T2=166; break;
- case '6' :case 'M':case 'N':case 'O': T1=290; T2=151; break;
- case '7' :case 'P':case 'Q':case 'R':case 'S': T1=263; T2=184; break;
- case '8' :case 'T':case 'U':case 'V': T1=263; T2=166; break;
- case '9' :case 'W':case 'X':case 'Y':case 'Z': T1=263; T2=151; break;
- case '*' : T1=238; T2=184; break;
- case '#' : T1=238; T2=151; break;
- }
-
- custom.dmacon=0x000f;
- custom.aud[1].ac_ptr=SnWave;
- custom.aud[2].ac_ptr=SnWave;
- custom.aud[1].ac_len=(UWORD)(sizeof(SnWaveData)/2);
- custom.aud[2].ac_len=(UWORD)(sizeof(SnWaveData)/2);
- custom.aud[1].ac_vol=(UWORD)64;
- custom.aud[2].ac_vol=(UWORD)64;
- custom.aud[1].ac_per=T1;
- custom.aud[2].ac_per=T2;
-
- custom.adkcon=0x00ff;
- custom.dmacon=0x8206;
-
- TimeDelay(UNIT_MICROHZ,0,delay*10000);
-
- custom.dmacon=0x0006;
-
- FreeVec(SnWave);
- }
- */
- /* /// */
-
-